package com.jdbc.lesson03;

import com.jdbc.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;


public class TestUpdate {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs = null;
        int i = 0;
        try {
            conn = JdbcUtils.getConnection();
            String sql = "update `users` set `birthday` = ? where `id` = 3";
            //预编译sql
            st = conn.prepareStatement(sql);
            st.setDate(1,new java.sql.Date(new Date().getTime()));
            i = st.executeUpdate();
            if(i > 0){
                System.out.println("修改成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JdbcUtils.release(conn,st,rs);
        }
    }
}
